package com.ruoyi.web.controller.bussiness;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.bo.SatisfactionBo;
import com.ruoyi.system.domain.vo.SatisfactionVo;
import com.ruoyi.system.service.ISatisfactionService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import java.util.Arrays;
import java.util.List;

/**
 * 勤务满意度统计
 *
 * @author ruoyi
 * @date 2025-06-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/satisfaction")
public class SatisfactionController extends BaseController {

    private final ISatisfactionService iSatisfactionService;

    /**
     * 查询勤务满意度统计列表
     */
    @SaCheckPermission("system:satisfaction:list")
    @GetMapping("/list")
    public TableDataInfo<SatisfactionVo> list(SatisfactionBo bo, PageQuery pageQuery) {
        return iSatisfactionService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出勤务满意度统计列表
     */
    @SaCheckPermission("system:satisfaction:export")
    @Log(title = "勤务满意度统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SatisfactionBo bo, HttpServletResponse response) {
        List<SatisfactionVo> list = iSatisfactionService.queryList(bo);
        ExcelUtil.exportExcel(list, "勤务满意度统计", SatisfactionVo.class, response);
    }

    /**
     * 获取勤务满意度统计详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:satisfaction:query")
    @GetMapping("/{id}")
    public R<SatisfactionVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iSatisfactionService.queryById(id));
    }

    /**
     * 新增勤务满意度统计
     */
    @SaCheckPermission("system:satisfaction:add")
    @Log(title = "勤务满意度统计", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SatisfactionBo bo) {
        return toAjax(iSatisfactionService.insertByBo(bo));
    }

    /**
     * 修改勤务满意度统计
     */
    @SaCheckPermission("system:satisfaction:edit")
    @Log(title = "勤务满意度统计", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SatisfactionBo bo) {
        return toAjax(iSatisfactionService.updateByBo(bo));
    }

    /**
     * 删除勤务满意度统计
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:satisfaction:remove")
    @Log(title = "勤务满意度统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iSatisfactionService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
